package com.level.restful.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.level.restful.dto.ResultInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.*;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import com.level.restful.entity.PageBean;
import com.level.restful.entity.TBuyGoods;
import com.level.restful.service.ITBuyGoodsService;

/**
 *  前端控制器
 *
 * @author 
 * @email 
 * @date 2021-01-24 15:25:41
 */
@Controller
@RequestMapping("/api/buyGoods")
public class TBuyGoodsController {
    @Resource
    private ITBuyGoodsService iTBuyGoodsService;

    @RequestMapping("/listData")
    public @ResponseBody
    ResultInfo<List<TBuyGoods>> listData( PageBean bean){
    	IPage<TBuyGoods> pageObj = iTBuyGoodsService.getList(bean);
        return new ResultInfo<>(pageObj.getRecords(), pageObj.getTotal());
    }

    /**
     * 购买商品
     * @param tBuyGoods
     * @return
     */
    @RequestMapping("/add")
    public @ResponseBody
    ResultInfo<Boolean> add( TBuyGoods tBuyGoods){
        boolean b = iTBuyGoodsService.buyGoods(tBuyGoods);
        return new ResultInfo<>(b);
    }

    @RequestMapping("/delBatch")
    public @ResponseBody
    ResultInfo<Boolean> delBatch(Integer[] idArr){
        boolean b = iTBuyGoodsService.removeByIds(Arrays.asList(idArr));
        return new ResultInfo<>(b);
    }

    @RequestMapping("/edit")
    public @ResponseBody
    ResultInfo<Boolean> edit(TBuyGoods tBuyGoods){
        boolean b = iTBuyGoodsService.updateById(tBuyGoods);
        return new ResultInfo<>(b);
    }

}
